package services

import (
	"lottery/dao"
	"lottery/datasource"
	"lottery/models"
)

type AwardService interface {
	Get(id int) *models.TbAward
	GetAll() []models.TbAward
	GetByEvent(eventId int) []models.TbAward
	CountAll() int64
	CountByEvent(eventId int) int64
	Update(data *models.TbAward, columns []string) error
	Create(data *models.TbAward) error
	DecrLeftNum(id, num int) (i int64, e error)
}

type awardService struct {
	dao *dao.AwardDao
}

func NewAwardService() AwardService {
	return &awardService{dao: dao.NewAwardDao(datasource.InstanceDbMaster())}
}

func (s *awardService) Get(id int) *models.TbAward {
	return s.dao.Get(id)
}

func (s *awardService) GetAll() []models.TbAward {
	return s.dao.GetAll()
}

func (s *awardService) GetByEvent(eventId int) []models.TbAward {
	return s.dao.GetByEvent(eventId)
}

func (s *awardService) CountAll() int64 {
	return s.dao.CountAll()
}

func (s *awardService) CountByEvent(eventId int) int64 {
	return s.dao.CountByEvent(eventId)
}

func (s *awardService) Update(data *models.TbAward, columns []string) error {
	return s.dao.Update(data, columns)
}

func (s *awardService) Create(data *models.TbAward) error {
	return s.dao.Create(data)
}

func (s *awardService) DecrLeftNum(id, num int) (i int64, e error) {
	return s.dao.DecrLeftNum(id, num)
}
